/**
 * 动态插入脚本
 * @param scripts
 * @returns {Promise<array>}
 */
export async function loadScripts (scripts) {
  function get (src) {
    return new Promise(function (resolve, reject) {
      var el = document.createElement("script");
      el.async = true;
      el.addEventListener("load", function () {
        resolve(src);
      }, false);
      el.addEventListener("error", function () {
        reject(src);
      }, false);
      el.src = src;
      (document.getElementsByTagName("body")[0] || document.getElementsByTagName("head")[0]).appendChild(el);
    });
  }

  const myPromises = scripts.map(async function (script, index) {
    return await get(script);
  });

  return await Promise.all(myPromises);
}
